package com.yh.homestay.controller;

import com.yh.homestay.aop.SystemLog;
import com.yh.homestay.common.CapitalGoodsResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.CapitalGoods;
import com.yh.homestay.service.CapitalGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 物资管理
 */
@Controller
public class CapitalGoodsController {
    @Autowired
    private CapitalGoodsService capitalGoodsService;
    //展示物资信息
    @RequestMapping(value = "/materiel/list")
    @ResponseBody
    @SystemLog(methods="物资展示", module = "物资管理")
    public HomeStayResult findAllMatriel(Integer page, Integer limit, String start, String end, String goodsName) {

        return capitalGoodsService.findAllCapitalGoods(page,limit,start,end,goodsName);
    }

    //添加物资
    @RequestMapping("/materiel/addMateriel")
    @ResponseBody
    @SystemLog(methods="添加物资", module ="物资管理")
    public CapitalGoodsResult addMateriel(CapitalGoods good) {
       //补全对象属性
        good.setGoodsType(1);
        good.setGoodsArea("仓库");
        return capitalGoodsService.addCapitalGood(good);
    }
    //删除物资
    @RequestMapping("/materiel/deleteSingleMateriel")
    @ResponseBody
    @SystemLog(methods="删除物资", module ="物资管理" )
    public CapitalGoodsResult delSingle(String goodsNumber) {
        return capitalGoodsService.delSingleCapitalGood(goodsNumber);
    }
    //批量删除物资
    @RequestMapping(value="/materiel/deleteMateriel")
    @ResponseBody
    @SystemLog(methods="删除多个物资", module ="物资管理" )
    public CapitalGoodsResult del(String nums) {

        return capitalGoodsService.delCapitalGood(nums);

    }
    //修改物资数据回显
    @RequestMapping("/materiel/toMaterieledit/{num}")
    @ResponseBody
    @SystemLog(methods="查看物资详情", module = "物资管理")
    public CapitalGoodsResult seleteCapitalSingle(@PathVariable String num) {
        return capitalGoodsService.seleteCapitalSingle(num);

    }
    //修改物资信息
    @RequestMapping("/materiel/updataMateriel")
    @ResponseBody
    @SystemLog(methods="修改物资信息", module = "物资管理")
    public CapitalGoodsResult updateMateriel(CapitalGoods good) {
        return capitalGoodsService.updataMaterielSingle(good);
    }


}
